<script setup lang="ts">
import { onMounted, ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { getCloudByTenant } from "@/api/cloud";
import { getAccount } from "@/utils/auth";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    pid: null,
    appName: null,
    cloudId: null,
    tenantId: null,
    appUrl: null,
    appDesc: null,
    appStatus: null,
    appOriginalUrl: null,
    editStatus: false
  })
});
const curTenantId = getAccount().tenantId;
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const cloudOptions = ref([]);
// cloudOptions.value = await getCloudByTenant(curTenantId);
function getRef() {
  return ruleFormRef.value;
}
onMounted(async () => {
  cloudOptions.value = await getCloudByTenant(curTenantId);

  // const { data } = await getRoleMenu();
  // treeIds.value = getKeyList(data, "id");
  // treeData.value = handleTree(data);
});
defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="120px"
  >
    <el-form-item label="应用名称" prop="appName">
      <el-input
        v-model="newFormInline.appName"
        clearable
        placeholder="请输入应用名称"
      />
    </el-form-item>
    <el-form-item label="服务云：" prop="cloudId">
      <el-select
        v-model="newFormInline.cloudId"
        placeholder="请选择发布服务云"
        clearable
        class="!w-[180px]"
      >
        <el-option
          v-for="item in cloudOptions"
          :key="item.pid"
          :label="item.cloudName"
          :value="item.pid"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="应用发布URI" prop="appUrl">
      <el-input
        v-model="newFormInline.appUrl"
        clearable
        placeholder="请输入应用发布URI"
      />
    </el-form-item>
    <el-form-item label="应用源地址" prop="appOriginalUrl">
      <el-input
        v-model="newFormInline.appOriginalUrl"
        clearable
        placeholder="请输入应用源地址"
      />
    </el-form-item>

    <el-form-item label="备注" prop="appDesc">
      <el-input
        v-model="newFormInline.appDesc"
        placeholder="请输入备注信息"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template>
